package com.donkingliang.imageselector.config;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.os.Build;

import androidx.core.app.ActivityCompat;

/**
 * 权限配置
 *
 * @author ydh
 * Time 2024年03月20日
 */
public class IsPermissionConfig {

    public static String[] permissionStorageAndCamera = new String[]{
            Manifest.permission.CAMERA,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE};

    public static String[] permissionStorage = new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE};

    public static String[] permissionStorage_33 = new String[]{"android.permission.READ_MEDIA_AUDIO", "android.permission.READ_MEDIA_VIDEO", "android.permission.READ_MEDIA_IMAGES"};

    public static String[] getPermissionStorage() {
        String[] s = permissionStorage;
        if (Build.VERSION.SDK_INT >= 33) {
            s = permissionStorage_33;
        }
        return s;
    }

    public static String[] getPermissionCamera() {
        String[] s = permissionStorageAndCamera;
        if (Build.VERSION.SDK_INT >= 33) {
            s = new String[]{
                    Manifest.permission.CAMERA,
                    Manifest.permission.READ_MEDIA_AUDIO,
                    Manifest.permission.READ_MEDIA_VIDEO,
                    Manifest.permission.READ_MEDIA_IMAGES};
        }
        return s;
    }

    public static boolean isPermission(Context context, String[] permissionStorage) {
        String[] var2 = permissionStorage;
        int var3 = permissionStorage.length;

        for (int var4 = 0; var4 < var3; ++var4) {
            String s = var2[var4];
            if (!isPermission(context, s)) {
                return false;
            }
        }

        return true;
    }

    public static boolean isPermission(Context context, String permission) {
        return ActivityCompat.checkSelfPermission(context, permission) == 0;
    }
}
